import 'package:flutter/material.dart';

class CommonTags extends StatelessWidget {
  final String title;
  final Color color;
  final Color backgroundColor;

  const CommonTags.origin(
    this.title, {
    Key? key,
    this.color = Colors.black,
    this.backgroundColor = Colors.grey,
  }) : super(key: key);

  factory CommonTags(String title) {
    switch (title) {
      case "近地铁":
        return CommonTags.origin(
          title,
          color: Colors.red,
          backgroundColor: Colors.red.shade100,
        );
      case "集中供暖":
        return CommonTags.origin(
          title,
          color: Colors.blue,
          backgroundColor: Colors.blue.shade100,
        );
      case "随时看房":
        return CommonTags.origin(
          title,
          color: Colors.green,
          backgroundColor: Colors.green.shade100,
        );
      case "新上":
        return CommonTags.origin(
          title,
          color: Colors.red,
          backgroundColor: Colors.red.shade100,
        );
      default:
        return CommonTags.origin(title);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(right: 5.0),
      padding: EdgeInsets.symmetric(horizontal: 5.0, vertical: 2.0),
      decoration: BoxDecoration(
        color: backgroundColor,
        borderRadius: BorderRadius.all(Radius.circular(10.0)),
      ),
      child: Text(
        title,
        style: TextStyle(color: color, fontSize: 10.0),
      ),
    );
  }
}
